Completed
Push — master ( 14a8cc...8b39c3 )
by Yannick
07:01
created

cesium-minimap.js ➔ ... ➔ _createToggleButton   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 10
rs 9.4285
nop 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A cesium-minimap.js ➔ ... ➔ btn.onclick 0 5 1
1
/*!
2
 * Cesium-minimap
3
 * Initial version from : https://github.com/knreise/cesium-minimap
4
 * Modified by Ycarus for Zugaina
5
 * Licensed under: BSD-3-Clause
6
 */
7
/*global Cesium:false*/
8
9
function CesiumMiniMap(parentViewer, options) {
10
    'use strict';
11
12
    options = options || {};
13
    var expanded = options.expanded || true;
14
    var _viewer, _container, _toggleButton;
15
16
    var CESIUM_OPTS = {
17
        animation: false,
18
        baseLayerPicker: false,
19
        fullscreenButton: false,
20
        geocoder: false,
21
        homeButton: false,
22
        infoBox: false,
23
        sceneModePicker: false,
24
        selectionIndicator: false,
25
        timeline: false,
26
        navigationHelpButton: false,
27
        navigationInstructionsInitiallyVisible: false,
28
        orderIndependentTranslucency: false,
29
        sceneMode: Cesium.SceneMode.SCENE2D,
0 ignored issues
show
Bug introduced by
The variable Cesium seems to be never declared. If this is a global, consider adding a /** global: Cesium */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
30
        mapProjection: new Cesium.WebMercatorProjection()
31
    };
32
33
    function _getContainer() {
34
        var parentDiv = document.createElement('div');
35
        parentDiv.className = 'cesium-minimap';
36
        parentViewer.bottomContainer.appendChild(parentDiv);
37
        return parentDiv;
38
    }
39
40
    function _addLayer(layer) {
41
        _viewer.imageryLayers.addImageryProvider(layer.imageryProvider);
42
    }
43
44
    function _setupMap(div) {
45
46
        CESIUM_OPTS.creditContainer = document.createElement('div');
47
48
        var miniviewer = new Cesium.Viewer(div, CESIUM_OPTS);
0 ignored issues
show
Bug introduced by
The variable Cesium seems to be never declared. If this is a global, consider adding a /** global: Cesium */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
49
        miniviewer.scene.imageryLayers.removeAll();
50
51
        var miniscene = miniviewer.scene;
52
        miniscene.screenSpaceCameraController.enableRotate = false;
53
        miniscene.screenSpaceCameraController.enableTranslate = false;
54
        miniscene.screenSpaceCameraController.enableZoom = false;
55
        miniscene.screenSpaceCameraController.enableTilt = false;
56
        miniscene.screenSpaceCameraController.enableLook = false;
57
58
        parentViewer.scene.imageryLayers.layerAdded.addEventListener(_addLayer);
59
60
        var pos = parentViewer.scene.camera.positionCartographic;
61
	pos.height = 22000000.0;
62
        miniviewer.scene.camera.setView({
63
            destination: Cesium.Ellipsoid.WGS84.cartographicToCartesian(pos),
64
        });
65
66
        _viewer = miniviewer;
67
    }
68
69
    function _setupListener() {
70
        var minicamera = _viewer.scene.camera;
71
        var parentCamera = parentViewer.scene.camera;
72
        parentCamera.moveEnd.addEventListener(function () {
73
            var pos = parentCamera.positionCartographic;
74
	    pos.height = Math.max(Math.min(pos.height,11000000) * 2, 100000);
75
            minicamera.setView({
76
                destination: Cesium.Ellipsoid.WGS84.cartographicToCartesian(pos),
0 ignored issues
show
Bug introduced by
The variable Cesium seems to be never declared. If this is a global, consider adding a /** global: Cesium */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
77
                orientation: {
78
            	    heading : parentCamera.heading,
79
            	    pitch : parentCamera.pitch
80
            	}
81
            });
82
        });
83
    }
84
85
    function _toggle() {
86
        expanded = !expanded;
87
88
        if (expanded) {
89
            _container.style.width = '150px';
90
            _container.style.height = '150px';
91
            _toggleButton.className = _toggleButton.className.replace(
92
                ' minimized',
93
                ''
94
            );
95
        } else {
96
            //close
97
            _container.style.width = '19px';
98
            _container.style.height = '19px';
99
            _toggleButton.className += ' minimized';
100
        }
101
    }
102
103
    function _createToggleButton() {
104
        var btn = document.createElement('a');
105
        btn.className = 'minimap-toggle-display';
106
        btn.onclick = function (e) {
107
            e.preventDefault();
108
            _toggle();
109
            return false;
110
        };
111
        return btn;
112
    }
113
114
115
    function init() {
116
        var div = document.createElement('div');
117
        div.className = 'minimap-container';
118
119
        _container = _getContainer();
120
        _container.appendChild(div);
121
        _toggleButton = _createToggleButton();
122
        _container.appendChild(_toggleButton);
123
        _setupMap(div);
124
        _setupListener();
125
        if (parentViewer.imageryLayers.length) {
126
            _addLayer(parentViewer.imageryLayers.get(0));
127
        }
128
    }
129
130
    init();
131
}